Skip to content

fix: Add GPT-5 Azure responses API support #6893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Aug 10, 2025

Summary

This PR fixes the issue where GPT-5 models on Azure OpenAI deployments were failing with a 400 Unsupported parameter: "messages" error. The problem was that GPT-5 models use the new responses API which expects an "input" parameter instead of the chat completions API "messages" parameter.

Changes

  • Added detection for GPT-5 models when using the OpenAI provider with Azure
  • Implemented support for the Azure responses API endpoint (/openai/responses)
  • Added proper formatting of conversation history into the "input" parameter format
  • Implemented support for GPT-5 specific parameters:
    • Reasoning effort (including "minimal" level)
    • Verbosity levels
    • Reasoning summary
    • Temperature and max_output_tokens
  • Added comprehensive streaming response handling for GPT-5 events
  • Fixed usage metrics processing to handle both GPT-5 and standard formats
  • Added comprehensive test coverage for GPT-5 Azure integration

Testing

  • All existing tests pass ✅
  • Added new tests specifically for GPT-5 Azure support
  • Tests verify correct API endpoint usage, parameter formatting, and response handling

Related Issue

Fixes #6862

How to Test

  1. Configure Roo Code with OpenAI Compatible provider
  2. Set up Azure OpenAI with a GPT-5 deployment
  3. Configure:
    • Base URL: https://<YOUR-RESOURCE>.openai.azure.com/openai/responses?api-version=2025-04-01-preview
    • Model: gpt-5
    • Use Azure: Yes
    • API Version: 2025-04-01-preview
    • Enable Reasoning Effort: Yes (set to desired level)
  4. Send a message - it should now work without the "messages" parameter error

cc @SannidhyaSah


Important

Fixes GPT-5 Azure API support by implementing the responses API and adding comprehensive tests.

  • Behavior:
    • Fixes 400 Unsupported parameter: "messages" error for GPT-5 models on Azure by switching to the responses API.
    • Implements handleGpt5ResponsesAPI() in openai.ts to format requests for GPT-5 models using Azure.
    • Adds support for GPT-5 specific parameters: reasoning effort, verbosity, reasoning summary, temperature, and max_output_tokens.
    • Updates processUsageMetrics() in openai.ts to handle both GPT-5 and standard formats.
  • Testing:
    • Adds tests in openai.spec.ts for GPT-5 Azure support, verifying API endpoint usage, parameter formatting, and response handling.
    • Tests include scenarios for different reasoning efforts and non-Azure usage.
  • Misc:
    • Adds isGpt5Model() and formatInputForResponsesAPI() helper functions in openai.ts.
    • Updates createMessage() in openai.ts to detect and handle GPT-5 models on Azure.

This description was created by Ellipsis for ecf2e1a. You can customize this summary. It will automatically update as commits are pushed.

- Detect GPT-5 models when using Azure OpenAI provider
- Use responses API endpoint with "input" parameter instead of chat completions "messages"
- Support GPT-5 specific parameters: reasoning effort (including minimal), verbosity, and reasoning summary
- Handle responses API streaming format for text, reasoning, and usage events
- Add comprehensive tests for GPT-5 Azure integration

Fixes #6862
@roomote roomote bot requested review from mrubens, cte and jr as code owners August 10, 2025 02:59
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Aug 10, 2025
const reader = body.getReader()
const decoder = new TextDecoder()
let buffer = ""
let hasContent = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'hasContent' is set in the streaming response handler but never used. Consider removing it if it isn’t needed.

Suggested change
let hasContent = false

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 10, 2025
Copy link
Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

/**
* Checks if the model ID is a GPT-5 model
*/
private isGpt5Model(modelId: string): boolean {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice there's a duplicate method here. The isGpt5Model() is defined twice - once at line 424 and the logic is already used inline at line 93. Should we consolidate to use a single method definition to avoid duplication?

// Azure URLs typically look like: https://<resource>.openai.azure.com/openai/responses?api-version=...
const urlParts = baseUrl.match(/^(https?:\/\/[^\/]+)(\/.*)?$/)
const azureBaseUrl = urlParts ? urlParts[1] : baseUrl
const responsesUrl = `${azureBaseUrl}/openai/responses`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Azure API version validated anywhere? For GPT-5 responses API, this parameter seems critical. Could we add validation to ensure it's present and in the expected format (e.g., '2025-04-01-preview' or later)?


// Extract the base URL without the path for Azure endpoints
// Azure URLs typically look like: https://<resource>.openai.azure.com/openai/responses?api-version=...
const urlParts = baseUrl.match(/^(https?:\/\/[^\/]+)(\/.*)?$/)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex pattern for URL extraction might be fragile with certain URL formats. Would it be safer to use the URL constructor for parsing? Something like:

Suggested change
const urlParts = baseUrl.match(/^(https?:\/\/[^\/]+)(\/.*)?$/)
const url = new URL(baseUrl);
const azureBaseUrl = `${url.protocol}//${url.host}`;
const responsesUrl = `${azureBaseUrl}/openai/responses`;

const reasoningEffort = this.getGpt5ReasoningEffort(reasoning)

// Build request body for GPT-5 responses API
const requestBody: any = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requestBody is typed as any. Could we create a proper TypeScript interface for the GPT-5 request body to improve type safety? This would help catch potential issues at compile time.

}
}
// Handle reasoning delta events
else if (
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we handling all possible GPT-5 streaming events? I'm wondering if there might be events like response.reasoning_effort.updated or other GPT-5 specific events we should handle. The Azure docs might have a complete list.

@@ -783,6 +836,166 @@ describe("OpenAiHandler", () => {
)
})
})

describe("GPT-5 Azure Support", () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test coverage! Though I'm wondering if we should add tests for error scenarios like malformed SSE data or network failures during streaming? These edge cases could help ensure robust error handling.

@spyridonas
Copy link

This is the implementation of this api, correct?
https://platform.openai.com/docs/guides/latest-model#migrating-from-chat-completions-to-responses-api

If so, can it be also added on OpenAI provider?

@spyridonas
Copy link

Also make sure you are giving the api the previous_response_id in a multi-turn conversion

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 12, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 12, 2025
@arnabbiswas1
Copy link

arnabbiswas1 commented Aug 12, 2025

  1. GPT-5 allows 4 reasoning levels: minimal, low, medium, high. When configuring Azure OpenAI GPT-5 using "API Provider" as "OpenAI Compatible ", reasoning effort "minimal" is not appearing in the drop down (only minimal, low, medium, high is available).

  2. With "OpenAI Compatible", "Enable Streaming" fails with temperature related issues.

@daniel-lxs daniel-lxs closed this Aug 14, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 14, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 14, 2025
@daniel-lxs
Copy link
Collaborator

Issue needs proper scoping

@daniel-lxs daniel-lxs deleted the fix/gpt5-azure-responses-api branch August 14, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR - Needs Preliminary Review size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

400 Unsupported parameter: 'messages'. error on OpenAI Compatible Azure deployment of GPT-5
5 participants